package config.mongodb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

@Configuration
@EnableMongoRepositories(basePackages = "com.ruiyi.kennedy.mongodb")
public class MongoConfig extends AbstractMongoConfiguration {
    @Autowired
    private Environment env;

    @Override
    public Mongo mongo() throws Exception {
        return new MongoClient(new ServerAddress(env.getProperty("mongo.host"), Integer.valueOf(env.getProperty("mongo.port"))));
    }

    @Override
    protected String getDatabaseName() {
        return "carassist";
    }

}
